$(document).ready(function () {
    const $expandBtn = $(".expand-btn");
    const $allLinks = $(".sidebar-links a");
    const $searchInput = $(".search__wrapper input");

    $expandBtn.on("click", function () {
        $("body").toggleClass("collapsed");
    });

    const current = window.location.href;

    $allLinks.on("click", function () {
        const hrefLinkClick = $(this).attr("href");

        $allLinks.each(function () {
            if ($(this).attr("href") === hrefLinkClick) {
                $(this).addClass("active");
            } else {
                $(this).removeClass("active");
            }
        });
    });

    $searchInput.on("focus", function () {
        $("body").removeClass("collapsed");
    });

    $searchInput.on("keypress", function (event) {
        if (event.which === 13) { // 检测回车键
            const query = encodeURIComponent($(this).val()); // 对查询参数进行编码
            window.location.href = '/queMan/getTopicsById?q=' + query;
        }
    });

});
